package com.mofang.powerdekorhelper.activity.card;

import android.app.Dialog;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.adapter.CardShopAdapter;
import com.mofang.powerdekorhelper.base.MvpActivity;
import com.mofang.powerdekorhelper.model.CardShop;
import com.mofang.powerdekorhelper.persenter.CardUserPresenter;
import com.mofang.powerdekorhelper.utils.LoadPrograss;
import com.mofang.powerdekorhelper.utils.T;
import com.mofang.powerdekorhelper.view.CardUseView;
import com.mofang.powerdekorhelper.witget.TitleBar;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;

/**
 * Created by luofei on 2017/8/23 0023.
 */

public class CardUseActivity extends MvpActivity<CardUseView, CardUserPresenter> implements CardUseView {

    private LoadPrograss loadPrograss;

    @BindView(R.id.card_use_title)
    TitleBar mTitleBar;

    @BindView(R.id.card_use_rv)
    RecyclerView recyclerView;

    private int card_id;
    private Dialog mDialog;
    private CardShopAdapter adapter;

    @Override
    public void initView() {
        inflateLayout(R.layout.activity_card_use_layout);
        initTitle();
        loadPrograss = new LoadPrograss(this);
    }

    @Override
    public void initData() {
        card_id = getIntent().getIntExtra("card_id", 0);

        if (card_id != 0) {
            try {
                presenter.getCardUse(new JSONObject().put("id", card_id).toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void setCardShop(CardShop cardShop) {
        if (cardShop.getResult() != null) {
            if (cardShop.getResult().size() > 0) {
                adapter = new CardShopAdapter(cardShop.getResult(), this, R.layout.card_shop_item_layout);
                recyclerView.setAdapter(adapter);
            }
        }
    }

    @Override
    public void showProgress() {
        loadPrograss.show();
    }


    @Override
    public void hideProgress() {
        loadPrograss.hide();
    }

    @Override
    public void toast(CharSequence s) {
        T.showShort(this, s);
    }

    @Override
    public void toast(int id) {

    }

    @Override
    public void showNullLayout() {

    }

    @Override
    public void hideNullLayout() {

    }

    @Override
    public void showErrorLayout(View.OnClickListener listener) {

    }

    @Override
    public void hideErrorLayout() {

    }

    @Override
    public void onError(String errorInfo) {
        loadPrograss.hide();
    }

    @Override
    public CardUserPresenter initPresenter() {
        return new CardUserPresenter();
    }

    private void initTitle() {
        initTitleBarWithback(mTitleBar, R.string.card_use_title);
    }
}
